/**
 * 
 */
package t4j.concurrency.deadlock;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class DeadlockingDiningPhilosophers {

	public static void main(String[] args) throws Exception {
		int ponder = 5;

		int size = 3;

		ExecutorService exec = Executors.newCachedThreadPool();

		Chopstick[] sticks = new Chopstick[size];

		for (int i = 0; i < size; i++)
			sticks[i] = new Chopstick();

		for (int i = 0; i < size; i++) {
			//这里的sticks[(i + 1) % size]是为了使最后一个哲学家右手拿的是0
			exec.execute(new Philosopher(sticks[i], sticks[(i + 1) % size], i, 0));

		}

		TimeUnit.SECONDS.sleep(10);

		exec.shutdownNow();
	}
}
